/**
  ******************************************************************************
  * @file           : dclcd.h
  * @brief          : Header for main.c file.
  *                   This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  *
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __DCLCD_H
#define __DCLCD_H

#include <stdint.h>
//#include "core_cm4.h"
#include "gui.h"
#include "parameter.h"

#define DCLCD_UART                     USART3
#define DCLCD_UART_BAUDRATE            230400
#define DCLCD_UART_IRQn                USART3_IRQn
#define DCLCD_UART_IRQHandler          USART3_IRQHandler
#define DCLCD_UART_EnableClock()       LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART3)
#define DCLCD_UART_IO_EnableClock()    LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOD)

#define DCLCD_UART_txDMA               DMA1
#define DCLCD_UART_txDMA_STREAM        LL_DMA_STREAM_3
#define DCLCD_UART_txDMA_CHANNEL       LL_DMA_CHANNEL_4
#define DCLCD_UART_txDMA_IRQn          DMA1_Stream3_IRQn
#define DCLCD_UART_txDMA_IRQHandler    DMA1_Stream3_IRQHandler

#define DCLCD_OUTTIMER                 TIM10
#define DCLCD_OUTTIMER_IRQn            TIM1_UP_TIM10_IRQn
#define DCLCD_OUTTIMER_IRQHandler      TIM1_UP_TIM10_IRQHandler
#define DCLCD_OUTTIMER_EnableClock()   LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM10)

#define DCLCD_GPIO_Port                GPIOD
#define DCLCD_GPIO_LL_AF               LL_GPIO_AF_7
#define DCLCD_TX_LL_Pin                LL_GPIO_PIN_8
#define DCLCD_RX_LL_Pin                LL_GPIO_PIN_9

#define DCLCD_RECV_QUE_LENGTH          15
#define DCLCD_RECV_QUE_ITEMSIZE        sizeof(DcLcd_RecvStru)

#define DCLCD_SEND_QUE_LENGTH          15
#define DCLCD_SEND_QUE_ITEMSIZE        sizeof(DcLcd_SendStru)

#define DCLCD_FRAME_MAXLEN             512

typedef struct _DcLcd_SendStru
{
  uint8_t  needreply;                          /* 是否需要回复 */
  uint8_t  reptimeout;                         /* 若需要回复,则等待超时时间 0~255ms */
  uint16_t cnt;
  uint8_t  buf[DCLCD_FRAME_MAXLEN];
  void (*replycb)(const uint8_t *buf, uint16_t len); /* 回复处理回调函数 */
}DcLcd_SendStru;

typedef struct _DcLcd_RecvStru
{
  uint16_t cnt;
  uint8_t  buf[DCLCD_FRAME_MAXLEN];
}DcLcd_RecvStru;

extern void dclcd_uart_init(void);
extern void dclcd_send_str(const char *buf);
extern void dclcd_send_buf(const uint8_t *buf, uint32_t len);
extern void dclcd_dma_send_buf(const uint8_t *buf, uint16_t len);

extern void dclcd_protc_init(void);

extern void dc_set_datetime(uint8_t bcd_year, uint8_t bcd_month, uint8_t bcd_day, uint8_t bcd_hour, uint8_t bcd_minute, uint8_t bcd_second);
extern void dc_cmd_change_screen(uint16_t sid);
extern void dc_cmd_buzzer(uint8_t t10ms);
extern void dc_cmd_fixcursor(uint8_t off0on1);
extern void dc_cmd_textfocus(uint16_t sid, uint16_t cid, uint8_t txf);
extern void dc_cmd_textflash(uint16_t sid, uint16_t cid, uint16_t cycle);
extern void dc_cmd_set_str(uint16_t sid, uint16_t cid, const char * str);
extern void dc_cmd_set_format(uint16_t sid, uint16_t cid, const char *format, ...);
extern void dc_comp_showhide(uint16_t sid, uint16_t cid, uint8_t show0hide1);
extern uint8_t dc_display_parainput(uint8_t page, uint8_t focus, const Sto_MaintainTableStru *mttb, const Sto_MaintainStru **pmt);
extern void dc_display_parainput_err(uint8_t err);
extern void dc_display_paralist(uint8_t page, uint8_t firstf, const Sto_MaintainTableStru *mttb);
extern void dc_load_calmessage(uint8_t nowpage, uint8_t nowfocus);
extern void dc_display_title(uint16_t ssid, const char *ts1, const char *ts2, const char *ts3, const char *ts4);

extern void dc_load_calzeroready(uint8_t nowpage, uint8_t nowfocus);
extern void dc_update_calzerorunning(uint8_t key);
extern void dc_load_calzeroend(uint8_t nowpage, uint8_t nowfocus);

extern void dc_load_calgmready(uint8_t nowpage, uint8_t nowfocus);
extern void dc_update_calgmrunning(uint8_t key);
extern void dc_load_calgmend(uint8_t nowpage, uint8_t nowfocus);

extern void dc_load_calswready(uint8_t nowpage, uint8_t nowfocus);
extern void dc_update_calswrunning(uint8_t key);
extern void dc_load_calswend(uint8_t nowpage, uint8_t nowfocus);

extern void dc_update_main(uint8_t key);

extern void dc_update_calgmrunning(uint8_t key);
extern void dc_display_state_pg1(void);
extern void dc_display_state_pg2(void);
extern void dc_display_state_pg3(void);
extern void dc_display_state_pg4(void);

extern void dc_update_sensorinfo(uint8_t idx);

extern const DcLcd_SendStru dclcd_cmd_get_datetime;
#define dc_cmd_get_datetime()    xQueueSend(dclcd_send_qhd, &dclcd_cmd_get_datetime, 0)

#endif /* __DCLCD_H */
